//
//  NavigationView.m
//  Menu
//
//  Created by YR on 2017/5/31.
//  Copyright © 2017年 YR. All rights reserved.
//

#import "NavigationView.h"

#import "Masonry.h"
#import "MenuViewController.h"

@interface NavigationView ()

@end

@implementation NavigationView
- (instancetype)init {
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64);
        self.backgroundColor = [UIColor blackColor];
        [self addSubview:self.titleLabel];
        [self addSubview:self.leftButton];
        [self addSubview:self.rightButton];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(33);
            make.width.mas_equalTo(170);
        }];
        [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_titleLabel.mas_centerY);
            make.left.mas_equalTo(16);
            make.size.mas_equalTo(CGSizeMake(44, 44));
        }];
        [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.titleLabel.mas_centerY);
            make.right.equalTo(self.rightButton.mas_left).with.offset(-4);
            make.size.mas_equalTo(CGSizeMake(44, 44));
        }];
        [self.leftButton setImage:[UIImage imageNamed:@"menu_icon"] forState:UIControlStateNormal];
        [self.leftButton addTarget:self action:@selector(leftTap) forControlEvents:UIControlEventTouchUpInside];
        
        [self.rightButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [self.rightButton addTarget:self action:@selector(rightTap) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

- (void)leftTap {
    [[MenuViewController shareInstance] show];
}

- (void)rightTap {
    
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"主界面";
        
    }
    return _titleLabel;
}

- (UIButton *)leftButton {
    if (!_leftButton) {
        _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    }
    return _leftButton;
}

- (UIButton *)rightButton {
    if (!_rightButton) {
        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    }
    return _rightButton;
}

@end
